<%@ page import="java.text.NumberFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.nus.beans.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.nus.beans.Project" %>
<%@ page import="com.nus.beans.UserType" %>
<%@ page import="org.apache.commons.lang3.StringEscapeUtils" %>
<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 9/21/12
  Time: 12:10 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>User Information</title></head>
<body>
<% User user = (User) request.getAttribute("targetUser");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    NumberFormat numberFormatter = NumberFormat.getInstance();
    User currentUser = (User) session.getAttribute("user");
    boolean isHRM = UserType.HR_MGR.equals(user.getUserType());
%>
<table>
    <tr>
        <td>Login Name:</td>
        <td><%=StringEscapeUtils.escapeXml(user.getLoginName())%></td>
    </tr>
    <tr>
        <td>First Name:</td>
        <td><%=StringEscapeUtils.escapeXml(user.getFirstName())%></td>
    </tr>
    <tr>
        <td>Family Name:</td>
        <td><%=StringEscapeUtils.escapeXml(user.getLastName())%></td>
    </tr>
    <tr>
        <td>Date Of Birth:</td>
        <td><%=formatter.format(user.getDateOfBirth())%></td>
    </tr>
    <tr>
        <td>Address:</td>
        <td><%=StringEscapeUtils.escapeXml(user.getAddress())%></td>
    </tr>
    <tr>
        <td>User Type:</td>
        <td><%=user.getUserType()%></td>
    </tr>
    <tr>
        <td>User Sub Type:</td>
        <td><%=user.getUserSubType()%></td>
    </tr>

   <% if(currentUser.getLoginName().equals(user.getLoginName()) || isHRM){ %>
    <tr>
        <td>Salary</td>
        <td><%=numberFormatter.format(user.getBasicSalary())%></td>
    </tr>

    <tr>
        <td>Leave Available</td>
        <td><%=user.getRemainingLeaves()%></td>
    </tr>
    <% } %>

    <%
    if(currentUser.getUserType().equals(UserType.DEVELOPER) || currentUser.getUserType().equals(UserType.PM)){
    %>
    <tr>
        <td>Projects</td>
        <td><%
            List<Project> projects = (List<Project>) request.getAttribute("projects");
            for (Project project : projects) {
        %> <%= StringEscapeUtils.escapeXml(project.getProjectName()) + "     " + project.getStatus()%>   <br/>
            <%}%></td>
    </tr>

    <% } %>
    <tr><td colspan="2"> <a href="viewHome.do">Home</a></td></tr>

</table>

</body>

</html>